package caiwei.android.activity.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import caiwei.android.R;
import caiwei.android.controls.SlideMenuItem;
import caiwei.android.controls.SlideMenuView;

/**
 * ActivityBase的上层封装类，用于封装与业务有关的一些通用成员
 * 
 * @author caiwei
 * @date2012-3-19
 * @version 1.0
 */
public class ActivityFrame extends ActivityBase
{
	private SlideMenuView mSlideMenuView;

	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.main);
		// 设置标题栏返回按键
		View view = findViewById(R.id.ivAppBack);
		OnBackListener _OnBackListener = new OnBackListener();
		view.setOnClickListener(_OnBackListener);

	}

	/**
	 * 动态加载主布局文件的主体内容布局
	 * 
	 * @param pResID
	 *            主体内容布局ID
	 */
	protected void appendMainBody(int pResID)
	{
		LinearLayout _LinearLayout = (LinearLayout) findViewById(getMainBodyLayoutID());
		View _View = LayoutInflater.from(this).inflate(pResID, null);
		RelativeLayout.LayoutParams _LayoutParams = new RelativeLayout.LayoutParams(
				LinearLayout.LayoutParams.FILL_PARENT,
				LinearLayout.LayoutParams.FILL_PARENT);
		_LinearLayout.addView(_View, _LayoutParams);
	}

	/**
	 * 获取主体布局ID
	 * 
	 * @return主体布局ID
	 */
	private int getMainBodyLayoutID()
	{
		return R.id.layMainBody;
	}

	/**
	 * 隐藏主布局Top栏中的返回图标
	 */
	protected void hideTitleBackButton()
	{
		findViewById(R.id.ivAppBack).setVisibility(View.GONE);
	}

	/**
	 * 创建滑动菜单
	 * 
	 * @param pResID
	 */
	protected void createSlideMenu(int pResID)
	{
		mSlideMenuView = new SlideMenuView(this);
		String[] _MenuItemArray = getResources().getStringArray(pResID);
		for (int i = 0; i < _MenuItemArray.length; i++)
		{
			SlideMenuItem _SliderMenuItem = new SlideMenuItem(i,
					_MenuItemArray[i]);
			mSlideMenuView.add(_SliderMenuItem);
		}
		mSlideMenuView.bindList();
	}

	/**
	 * 设置窗体标题栏文字
	 * 
	 * @param pTitle
	 */
	protected void setTopBarTitle(String pTitle)
	{
		TextView _TextView = (TextView) findViewById(R.id.tvTopTitle);
		_TextView.setText(pTitle);
	}

	/**
	 * 标题栏返回标监听器
	 * 
	 * @author caiwei
	 * @date2012-3-7
	 * @version 1.0
	 */
	private class OnBackListener implements android.view.View.OnClickListener
	{
		public void onClick(View view)
		{
			finish();
		}
	}

	/**
	 * 移除底边框
	 */
	protected void removeBottomBox()
	{
		mSlideMenuView = new SlideMenuView(this);
		mSlideMenuView.removeBottomBox();
	}
}
